import { getPackageJSON, resolvePackagePath, getBaseRollupPlugins } from './utils';
import generatePackageJson from 'rollup-plugin-generate-package-json';
import alias from '@rollup/plugin-alias';

const { name, module, peerDependencies } = getPackageJSON('react-dom');
const pkgPath = resolvePackagePath(name);
const distPkgPath = resolvePackagePath(name, true);

export default [
	{
		input: `${pkgPath}/${module}`,
		output: [
			{
				file: `${distPkgPath}/index.js`,
				name: 'ReactDom',
				format: 'umd',
			},
			{
				file: `${distPkgPath}/client.js`,
				name: 'client',
				format: 'umd',
			},
		],
		external: [...Object.keys(peerDependencies)],
		plugins: [
			...getBaseRollupPlugins(),
			//  用于在打包产物中生成package.json
			alias({
				entries: {
					hostConfig: `${pkgPath}/src/hostConfig.ts`,
				},
			}),
			generatePackageJson({
				// 哪个文件夹下的package.json
				inputFolder: pkgPath,
				// 哪个文件夹下创建package.json
				outputFolder: distPkgPath,
				// 输出的package.json包含哪些内容
				baseContents: ({ name, description, version }) => ({
					name,
					description,
					version,
					main: 'index.js',
					peerDependencies: {
						react: version,
					},
				}),
			}),
		],
	},
];
